package com.sc.VenusQueryBeta.presenter.account.zhuanma;


import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.account.zhuanma.ZhuanMaContract;
import com.sc.VenusQueryBeta.model.account.zhuanma.ZhuanMaModel;
import com.sc.VenusQueryBeta.model.bean.account.AccountList;
import com.sc.VenusQueryBeta.model.bean.account.AllRoomListBean;
import com.sc.VenusQueryBeta.model.bean.account.CurrencyListBean;
import com.sc.VenusQueryBeta.model.bean.account.MaxChangemonthBean;

import io.reactivex.functions.Consumer;

/**
 * Created by SC-02 on 2018/9/19.
 * 转码明细presenter 继承契约类的presenper
 */

public class ZhuanMaPresenter extends ZhuanMaContract.ZhuanMaPresenter {
    @Override
    protected ZhuanMaContract.IZhuanMaModel getModel() {
        return ZhuanMaModel.newInstance();
    }

    @Override
    public void onStart() {

    }

    /**
     * 实例化对象
     * @return
     */
    public static ZhuanMaPresenter newInstance(){
        return new ZhuanMaPresenter();
    }

    /**
     * 查询厅
     * @param serverAddress
     * @param projectName
     * @param serverPort
     */
//    @Override
//    public void queryAllRoomList(String serverAddress, String projectName, int serverPort) {
//        if (mRxManager != null && mIModel != null) {
//            mRxManager.register(mIModel.queryCurrencyList(serverAddress, projectName, serverPort).subscribe(new Consumer<CurrencyListBean>() {
//                @Override
//                public void accept(CurrencyListBean currencyListBean) throws Exception {
//                    mIView.showqueryCurrencyList(currencyListBean);
//                }
//            }, new Consumer<Throwable>() {
//                @Override
//                public void accept(Throwable throwable) throws Exception {
//                    LogUtils.e("Network error." + throwable.getMessage());
////                if (mIView != null)
////                    return;
//                    mIView.showToast("Network error.");
//                    mIView.showAllRoomNetworkError(throwable);
//                }
//            }));
//        }else {
//
//        }
//    }

    /**
     * 查询子户口
     * @param serverAddress
     * @param projectName
     * @param serverPort
     * @param clientindex
     * @param roomyear
     * @param roommonth
     * @param recognitionValue
     * @param depositType
     */
    //A,B码
//    @Override
//    public void queryClientReserved02(String serverAddress, String projectName, int serverPort, int clientindex, String roomyear, String roommonth, String recognitionValue, String depositType, int chiptype) {
//        if (mRxManager != null && mIModel != null) {
//            mRxManager.register(mIModel.queryZiHuList(serverAddress, projectName, serverPort, clientindex,  roomyear,
//                    roommonth, recognitionValue, depositType,chiptype).subscribe(new Consumer<AccountList>() {
//                @Override
//                public void accept(AccountList accountListBean) throws Exception {
//                    mIView.showZiHuKouList(accountListBean);
//                }
//            }, new Consumer<Throwable>() {
//                @Override
//                public void accept(Throwable throwable) throws Exception {
//                    LogUtils.e("错误查询子户口" + throwable.getMessage());
////                if (mIView != null)
////                    return;
//                    mIView.showToast("Network error." + throwable.getMessage());
//                    mIView.showNetworkError(throwable);
//                }
//            }));
//        }else {
//
//        }
//    }

    /**
     * 查詢最大日期
     * @param serverAddress
     * @param projectName
     * @param serverPort
     */
//    @Override
//    public void queryMaxChangemonth(String serverAddress, String projectName, int serverPort, int roomid) {
//        if (mRxManager != null && mIModel != null) {
//            mRxManager.register(mIModel.queryMaxChangemonth(serverAddress, projectName, serverPort, roomid).subscribe(new Consumer<MaxChangemonthBean>() {
//                @Override
//                public void accept(MaxChangemonthBean allRoomListBean) throws Exception {
//                    mIView.showMaxChangemonthList(allRoomListBean);
//                }
//            }, new Consumer<Throwable>() {
//                @Override
//                public void accept(Throwable throwable) throws Exception {
//
//                    LogUtils.e("Network error." + throwable.getLocalizedMessage());
////                mIView.showToast("Network error."+throwable.getMessage());
//                    mIView.showNetworkError(throwable);
//                }
//            }));
//        }else {
//
//        }
//    }

    @Override
    public void queryCurrencyList(String serverAddress, String projectName, int serverPort) {
        if (mRxManager != null && mIModel != null) {
            mRxManager.register(mIModel.queryCurrencyList(serverAddress, projectName, serverPort).subscribe(new Consumer<CurrencyListBean>() {
                @Override
                public void accept(CurrencyListBean currencyListBean) throws Exception {
                    mIView.showqueryCurrencyList(currencyListBean);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    LogUtils.e("Network error." + throwable.getMessage());
//                if (mIView != null)
//                    return;
                    mIView.showToast("Network error.");
                    mIView.showAllRoomNetworkError(throwable);
                }
            }));
        }else {

        }
    }

    @Override
    public void queryClientReserved02(String serverAddress, String projectName, int serverPort, int clientindex, String roomyear, String roommonth, String recognitionValue, String depositType,String  currencynameCN) {
        if (mRxManager != null && mIModel != null) {
            mRxManager.register(mIModel.queryZiHuList(serverAddress, projectName, serverPort, clientindex,  roomyear,
                    roommonth, recognitionValue, depositType,currencynameCN).subscribe(new Consumer<AccountList>() {
                @Override
                public void accept(AccountList accountListBean) throws Exception {
                    mIView.showZiHuKouList(accountListBean);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    LogUtils.e("错误查询子户口" + throwable.getMessage());
//                if (mIView != null)
//                    return;
                    mIView.showToast("Network error." + throwable.getMessage());
                    mIView.showNetworkError(throwable);
                }
            }));
        }else {

        }
    }


}
